package com.hlk.config;

import com.hlk.interceptors.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author hlk
 * @version 1.0
 * @date 2020-12-17 11:36
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    private PassportInterceptor passportInterceptor;
    @Autowired
    private UserTokenInterceptor userTokenInterceptor;
    @Autowired
    private UserActiveInterceptor userActiveInterceptor;
    @Autowired
    private AdminTokenInterceptor adminTokenInterceptor;
    @Autowired
    private AritcleReadInterceptor aritcleReadInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(passportInterceptor).addPathPatterns("/passport/getSMSCode");

        registry.addInterceptor(userTokenInterceptor)
                .addPathPatterns("/user/getAccountInfo")
                .addPathPatterns("/user/updateUserInfo");

        registry.addInterceptor(userActiveInterceptor)
                .addPathPatterns("/fs/uploadSomeFiles")
                .addPathPatterns("/fans/follow")
                .addPathPatterns("/fans/unfollow");

        registry.addInterceptor(adminTokenInterceptor)
                .addPathPatterns("/adminMng/adminIsExist")
                .addPathPatterns("/adminMng/addNewAdmin")
                .addPathPatterns("/adminMng/getAdminList")
                .addPathPatterns("/fs/uploadToGridFS")
                .addPathPatterns("/fs/readInGridFS")
                .addPathPatterns("/friendLinkMng/saveOrUpdateFriendLink")
                .addPathPatterns("/friendLinkMng/getFriendLinkList")
                .addPathPatterns("/friendLinkMng/delete")
                .addPathPatterns("/categoryMng/saveOrUpdateCategory")
                .addPathPatterns("/categoryMng/getCatList");

        registry.addInterceptor(aritcleReadInterceptor)
                .addPathPatterns("/portal/article/readArticle");
    }
}
